package com.cmc.cloud.cmclink.doc.controller.admin;

import com.cmc.cloud.cmclink.doc.vo.doinfovo.DoInfoCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.doinfovo.DoInfoPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.doinfovo.DoInfoRespVO;
import com.cmc.cloud.cmclink.doc.vo.doinfovo.DoInfoUpdateReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.DoInfoDO;
import com.cmc.cloud.cmclink.doc.convert.DoInfoConvert;
import com.cmc.cloud.cmclink.doc.service.DoInfoService;


/**
 * 进口单证do前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 进口单证do")
@RestController
@Validated
@RequestMapping("/admin-api/doc/v1/do-info")
public class DoInfoController {

    @Resource
    private DoInfoService doInfoService;

    @Operation(summary = "创建进口单证do")
	@PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:do-info:create')")
    public CommonResult<Void> createDoInfo(@Valid @RequestBody DoInfoCreateReqVO createReqVO) {
        doInfoService.createDoInfo(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新进口单证do")
	@PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:do-info:update')")
    public CommonResult<Void> updateDoInfo(@Valid @RequestBody DoInfoUpdateReqVO updateReqVO) {
        doInfoService.updateDoInfo(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除进口单证do")
	@PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('doc:do-info:delete')")
    public CommonResult<Void> deleteDoInfo(@PathVariable("id") Long id) {
        doInfoService.deleteDoInfo(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得进口单证do")
	@GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('doc:do-info:query')")
    public CommonResult<DoInfoRespVO> getDoInfo(@PathVariable("id") Long id) {
        DoInfoDO doInfo = doInfoService.getDoInfo(id);
        return CommonResult.success(DoInfoConvert.INSTANCE.convert(doInfo));
    }

    @Operation(summary = "获得进口单证do列表")
	@GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:do-info:query')")
    public CommonResult<List<DoInfoRespVO>> getDoInfoList(@RequestParam("ids") Collection<Long> ids) {
        List<DoInfoDO> list = doInfoService.getDoInfoList(ids);
        return CommonResult.success(DoInfoConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得进口单证do分页")
	@GetMapping("/page")
    @PreAuthorize("@ss.hasPermission('doc:do-info:query')")
    public CommonResult<PageResult<DoInfoRespVO>> getDoInfoPage(@Valid DoInfoPageReqVO pageVO) {
        PageResult<DoInfoDO> pageResult = doInfoService.getDoInfoPage(pageVO);
        List<DoInfoRespVO> results = DoInfoConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
